<?php include('../../job/common/pdata_mysql.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>插入项目</title>
<style type="text/css">
.modi input {
	width: 350px;
	height: 30px;
}
.modi textarea {
	width: 350px;
	height: 50px;
}
.modi {
	font-size: 10px;
	width: 960px;
}
#stEdit {
	float: left;
	width: 960px;
}
</style>
<link href="/css/allstyle.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="header"><?php include("../../job/common/header.php") ?></div>
<?php
  	if(isset($_REQUEST['insert']))
	{
		//$pid = $_REQUEST['pid'];
		$projectname = $_REQUEST['projectname'];
		$oldname = $_REQUEST['oldname'];
		$startdate = $_REQUEST['startdate'];
		$enddate = $_REQUEST['enddate'];

		if(isset($_REQUEST['donedraft']))
			$donedraft = $_REQUEST['donedraft'];
		else
			$donedraft = 0;
		
		$sql = "INSERT INTO project (`projectname`, `oldname`, `donedraft`, `startdate`, `enddate`) VALUES ('".$projectname."','".$oldname."','".$donedraft."','".$startdate."','".$enddate."')";
		
		echo "<p>".$sql."</p>";
		
		$conn = mysql_pconnect($hostname_pdata,$username_pdata,$password_pdata);
		mysql_select_db("pdata");
		if($rs = mysql_query($sql,$conn) or $error=die(mysql_error()))
		{
			$pid = mysql_insert_id($conn);
			$sql = "select * from project where pid = '". $pid."'";
			$rs = mysql_query($sql,$conn);
			$row = mysql_fetch_array($rs) or die(mysql_error()); 
			
			$pid = $row['pid'];
			$projectname = $row['projectname'];
			$oldname = $row['oldname'];
			$donedraft = $row['donedraft'];
			$startdate = $row['startdate'];
			$enddate = $row['enddate'];
			
			echo "Insert Succeed!";
		}
		else
		{
			echo "Insert missed!Check the data and insert again!";
		}

		
		mysql_close($conn);
	}
	else
	{
		$pid = "";
		$projectname = "";
		$oldname = "无";
		$donedraft = 0;
		$startdate = "无";
		$enddate = "无";
	}?>
<div id="wrap">
    <h1>准备插入新的输变电工程</h1>
    <form id="station" name="station" method="get" action="pro_insert.php">
    
      <table class="modi">
        <tr>
          <th width="120">项目</th>
          <th width="360">内容</th>
          <th width="120">项目</th>
          <th width="360">内容</th>
        </tr>
        <tr>
          <td>工程序号</td>
          <td><input name="pid" type="text" id="pid" value="<?php echo $pid; ?>"  /></td>
          <td>完成与否</td>
          <td><input name="donedraft" type="text" id="donedraft" value="<?php echo $donedraft; ?>" /></td>
        </tr>
        <tr>
          <td>工程名称</td>
          <td><input name="projectname" type="text" id="projectname" value="<?php echo $projectname; ?>" /></td>
          <td>曾用名称</td>
          <td><input name="oldname" type="text" id="oldname" value="<?php echo $oldname; ?>" /></td>
        </tr>
        <tr>
          <td>首次开始日期</td>
          <td><input name="startdate" type="text" id="startdate" value="<?php echo $startdate; ?>" /></td>
          <td>送电或结束日期</td>
          <td><input name="enddate" type="text" id="enddate" value="<?php echo $enddate; ?>" /></td>
        </tr>
      </table>
      <input name="insert" type="submit" class="modi" id="insert" value="插入" />
    </form>
</div>
<div id="footer"><?php include("../../job/common/footer.php") ?></div>
</body>
</html>